package com.eypg.service.impl;

import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.stereotype.Service;

import com.eypg.dao.BaseDAO;
import com.eypg.pojo.Product;
import com.eypg.service.ProductService;
@Service("productService")
public class ProductServiceImpl implements ProductService{
	@Autowired
	@Qualifier("baseDao")
	BaseDAO baseDao;

	public void addProduct(Product product) {
		baseDao.saveOrUpdate(product);
	}

	public void delProduct(int id) {
		baseDao.delById(Product.class, id);
	}

	public void updateProduct(String hql) {
		baseDao.update(hql);
	}

	@SuppressWarnings("unchecked")
	public List<Product> queryProduct(String hql) {
		return (List<Product>)baseDao.query(hql);
	}

	public Product loadProductByName(String productName) {
		String hql = " from Product p where p.productName='" + productName + "'";
		
		return (Product)baseDao.loadObject(hql);
	}
	
}
